
{% extends 'home/public/base.html' %}

{% block js %}
	<link rel="stylesheet" type="text/css" href="/static/home/public/css/order.css">
	<link rel="stylesheet" type="text/css" href="/static/home/public/css/order-app.css">

{% endblock %}

{% block con %}
<div class="mainbody order">
	<div class="container">
		<!-- 面包屑导航 -->
		<div class="crumbs col-xs-12 col-sm-12">
			<ol class="breadcrumb">
				<li class="hidden-xs hidden-sm"><a href="{% url 'index' %}">首页</a></li>
				<li class="hidden-xs hidden-sm"><a href="member.html">我的商城</a></li>
				<li class="">个人中心</li>
				<li class="active">地址管理</li>

			</ol>
		</div><!-- 面包屑导航 E-->
		
		<div class="main clearfix">
			<!-- 左侧导航 -->
			<div class="left-nav f-fl col-md-4 hidden-xs hidden-sm">
				<div class="nav-main">
					<a href="{% url 'orderuser' %}" class="type-title"><span class="glyphicon glyphicon-list-alt" aria-hidden="true"></span>订单中心</a>
					<a href="{% url 'orderuser' %}" class="ml ">我的订单</a>
					<a href="#" class="ml ">我的回购单</a>
					<a href="#" class="ml ">我的意外保</a>
					<a href="{% url 'orderone' %}" class="type-title"><span class="glyphicon glyphicon-user" aria-hidden="true"></span>个人中心</a>
					<a href="{% url 'orderadd' %}" class="ml active">地址管理</a>
					<a href="#" class="ml ">我的收藏</a>
					<a href="#" class="ml ">消息提醒</a>
					<a href="#" class="ml ">建议反馈</a>
				</div>
			</div><!-- 左侧导航 E-->
			<!-- 右侧内容展示 -->
			<div class="right-content f-fr col-md-8 col-xs-12 col-sm-12">
				<table class="table table-hover">
				 	

					<button type="butt 
					on" class="btn btn-primary" data-toggle="modal"  data-target="#exampleModal" data-whatever="@mdo" style="width:100px;margin-right: 0px;margin-bottom: 20px ">添加地址</button>
					
					
				
 						
 			
 					<tr style="height:50px">
 						<td>收件人</td>
 						<td>联系电话</td>
						<td>收货地址</td>
						<td>默认地址</td>
						<td>操作</td>
 					</tr>
 					{% for i in ob %}
 					<tr>
 						<td>{{ i.aname }}</td>
 						<td>{{ i.aphone }}</td>
 						<td>{{ i.adds }}</td>
 						{% if i.status == 1 %}
 						<td style="color:red">默认地址</td>
 						{% else %}
 						<td><span class="defaults" style="color:blue" href="" aid="{{ i.id }}" >设为默认</span></td>
 						{% endif %}
 						<td>
 							<a class="edits" href=""  data-toggle="modal" aid="{{ i.id }}" data-target="#edit" data-whatever="@mdo"  style="color:blue" >编辑</a>

					
 						</td>
 					</tr>
 					{% endfor %}

 					
				</table>

				<!--添加 -->
				<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
				  <div class="modal-dialog" role="document">
				    <div class="modal-content">
				      <div class="modal-header">
				        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
				        <h4 class="modal-title" id="exampleModalLabel">地址添加</h4>
				      </div>
				      <div class="modal-body">
				        <form action="{% url 'orderadds'  %}">
				          <div class="form-group">
				            <label for="recipient-name" class="control-label">收货人:</label>
				            <input type="text" class="form-control" name="aname" id="recipient-name">
				          </div>

				           <div class="form-group">
				            <label for="recipient-name" class="control-label">收货地址:</label>
				            <input type="text" class="form-control" name="adds" id="recipient-name">
				          </div>

				           <div class="form-group">
				            <label for="recipient-name" class="control-label">联系电话:</label>
				            <input type="text" class="form-control" name="aphone" id="recipient-name">
				          </div>
				         
				        <label>
                      		<input name="status" value="1" type="checkbox"> 是否设为默认地址
                    	</label>

				  
					      </div>
					      <div class="modal-footer">
				      
				        <button  class="btn btn-primary">提交</button>
				        </form>


				      </div>
				    </div>
				  </div>
				</div>
				 							<!-- 编辑 -->

							<div class="modal fade" id="edit" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
							  <div class="modal-dialog" role="document">
							    <div class="modal-content">
							      <div class="modal-header">
							        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
							        <h4 class="modal-title" id="exampleModalLabel">订单编辑</h4>
							      </div>
							      	<div class="modal-body">
							        <form action="{% url 'editinsert'  %}">
							          <div class="form-group">
							            <label for="recipient-name" class="control-label ">收件人:</label>
							            <input type="text" class="form-control aname" name="aname" id="recipient-name">
							          </div>	
							          <input class="ppp" type="hidden" name="aid" value="">

							           <div class="form-group">
							            <label for="recipient-name" class="control-label  ">收件地址</label>
							            <input type="text" class="form-control adds" name="adds" id="recipient-name">
							          </div>

							           <div class="form-group">
							            <label for="recipient-name" class="control-label ">联系电话:</label>
							            <input type="text" class="form-control aphone" name="aphone" id="recipient-name">
							          </div>
							         
								       

							  
								     </div>
								    <div class="modal-footer">
							        <button name='edit' value="1" class="btn btn-primary">删除</button>
							      
							        <button name='edit' value="2" class="btn btn-primary">修改</button>
							        </form>


							     	</div>
							    </div>
							  </div>
							</div>


				
			</div>
		</div>
	</div>	
</div>

<script type="text/javascript">
// 设置默认的ajax
$('.defaults').click(function(){
	var aid = $(this).attr("aid")
	$.ajaxSetup({data:{csrfmiddlewaretoken:'{{ csrf_token }}'}});
	$.post('{% url "orderadd" %}',{aid:aid},function(){
		location.href=location.href;
	})
})
//设置编辑的ajax
$(".edits").click(function(){
	//获取aid
	var aid=$(this).attr("aid")

	//发送ajax
	$.get("{% url 'orderedit'  %}",{aid:aid},function(data){
		$(".aname").val(data["aname"])
		$(".aphone").val(data["aphone"])
		$(".adds").val(data["adds"])
		$(".ppp").val(aid)
	})

})



// 模态框不显示的js
$("#exampleModal").modal({
    backdrop:false,
    keyboard:false,
    show:false,
});
// 模态框不显示的js
$("#edit").modal({
    backdrop:false,
    keyboard:false,
    show:false,
});

</script>


{% endblock %}